const { UUIDV4, UUID, STRING, TEXT, JSON, Model } = require('sequelize');
const db = require('../../helpers/db');

class GoodsComment extends Model {}

GoodsComment.init(
    {
        id: {
            type: UUID,
            defaultValue: UUIDV4,
            primaryKey: true,
            comment: '商品评论ID'
        },
        imageList: {
            type: STRING(512),
            comment: '图片列表',
            allowNull: false,
            field: 'image_list'
        },
        content: {
            type: TEXT,
            comment: '评论内容',
            allowNull: false
        },
        goods: {
            type: UUID,
            comment: '外键，商品ID'
        },
        orderItem: {
            type: UUID,
            unique: true,
            comment: '外键，订单项ID',
            field: 'order_item'
        },
        fromUser: {
            type: UUID,
            unique: true,
            comment: '外键，留言者ID',
            field: 'from_user'
        },
        toUser: {
            type: UUID,
            comment: '外键，回复对象ID',
            field: 'to_user'
        }
    },
    {
        tableName: 'goods_comment',
        underscored: true,
        sequelize: db
    }
);

module.exports = GoodsComment;
